<?php
    include_once "app/connection.php";
    include_once "app_sv/check_user.php";   
    
    $sql = mysql_query("SELECT * FROM hocky WHERE HOCKY=(SELECT MAX(HOCKY) FROM hocky WHERE NAM=(SELECT MAX(NAM) FROM hocky))
        AND NAM=(SELECT MAX(NAM) FROM hocky)");
    $row = mysql_fetch_assoc($sql);    
    $hocky = $row['HOCKY'];
    $nam = $row['NAM']; 

    if($is_sv) {
?>    
    <center><h2>KẾT QUẢ ĐĂNG KÝ MÔN HỌC</h2>
    <?php    echo "<h3> HỌC KỲ ".$row['HOCKY']." NĂM ".$row['NAM']." </h3></center>"; ?>

    <div style="width: 690px; min-height: 300px; overflow-y: scroll; margin: 0 auto;">
<?php
        $sql = mysql_query("SELECT * FROM sinhvien WHERE MSSV = '".$_SESSION['s_user']."'");
        $sv = mysql_fetch_assoc($sql);
        
        echo "<center><b><i>Mã số SV: </i></b>".$sv['MSSV']." - ";
        echo "<b><i>Họ và tên: </i></b>".$sv['HOTEN']." - ";
        echo "<b><i>Lớp: </i></b>".$sv['MAKHOA'].'.'.$sv['KHOAHOC'].'</center><br />';
           
?>
        <center><table class="danhsach">        
            <tr style="background: #247CB9;">
                <td style="text-align: center; color: #fff;">Mã lớp</td>
                <td style="text-align: center; color: #fff;">Tên Môn học</td>
                <td style="text-align: center; color: #fff;">Tên Giảng viên</td>
                <td style="text-align: center; color: #fff;">Ca</td>
                <td style="text-align: center; color: #fff;">Thứ</td>                    
                <td style="text-align: center; color: #fff;">Phòng</td>
                <td style="text-align: center; color: #fff;">Số TC</td>
            </tr>
<?php
            $tong_tc = 0;
            $sql = mysql_query("SELECT * FROM dangky, lop, giaovien, monhoc 
                WHERE dangky.MAMONHOC = monhoc.MAMONHOC AND dangky.MALOP = lop.MALOP AND dangky.MAMONHOC = lop.MAMONHOC
                AND giaovien.MAGIAOVIEN = lop.MAGIAOVIEN AND MSSV = '".$_SESSION['s_user']."' AND dangky.NAM = lop.NAM
                AND dangky.HOCKY = lop.HOCKY AND dangky.HOCKY = '$hocky' AND dangky.NAM = '$nam'");
            while($rows = mysql_fetch_assoc($sql))
            {
                echo '<tr>';
                echo "<td style='text-align: center'>".$rows['MAMONHOC'].".".$rows['MALOP']."</td>";
                echo "<td>".$rows['TENMONHOC']."</td>";
                echo "<td>".$rows['HOTEN']."</td>";
                echo "<td style='text-align: center'>".$rows['CA']."</td>";
                echo "<td style='text-align: center'>".$rows['THU']."</td>";
                echo "<td style='text-align: center'>".$rows['PHONG']."</td>";
                echo "<td style='text-align: center'>".$rows['TINCHILYTHUYET']."</td>"; $tong_tc += $rows['TINCHILYTHUYET'];
                echo '</tr>';
            }
            echo '<tr>';
            echo "<td></td> <td></td>";
            echo "<td colspan='4' style='text-align: center'><b><i>Tổng tín chỉ đã đăng ký:</i></b></td>";
            echo "<td style='text-align: center'><b><i>".$tong_tc."</i></b></td>";
?>
        </table></center><br />
        </div>
        
        <a href="?page=dkmh"><button>SỬA</button></a>
        <a href="../"><button>IN</button></a>
<?php   }
    else echo "Bạn không được truy cập vào đây.";
 ?>
